package com.example.express.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.util.Collection;
import java.util.Objects;

@Entity
public class CustomerInfo {
    private int id;
    private String name;
    private String telCode;
    private String department;
    private String regionCode;
    private String address;
    private Integer postCode;
    private Collection<ExpressSheet> fromMe;
    private Collection<ExpressSheet> toMe;

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "Name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "TelCode")
    public String getTelCode() {
        return telCode;
    }

    public void setTelCode(String telCode) {
        this.telCode = telCode;
    }

    @Basic
    @Column(name = "Department")
    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    @Basic
    @Column(name = "RegionCode")
    public String getRegionCode() {
        return regionCode;
    }

    public void setRegionCode(String regionCode) {
        this.regionCode = regionCode;
    }

    @Basic
    @Column(name = "Address")
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Basic
    @Column(name = "PostCode")
    public Integer getPostCode() {
        return postCode;
    }

    public void setPostCode(Integer postCode) {
        this.postCode = postCode;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CustomerInfo that = (CustomerInfo) o;
        return id == that.id &&
                Objects.equals(name, that.name) &&
                Objects.equals(telCode, that.telCode) &&
                Objects.equals(department, that.department) &&
                Objects.equals(regionCode, that.regionCode) &&
                Objects.equals(address, that.address) &&
                Objects.equals(postCode, that.postCode);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, telCode, department, regionCode, address, postCode);
    }

    @JsonIgnore
    @OneToMany(mappedBy = "sender")
    public Collection<ExpressSheet> getFromMe() {
        return fromMe;
    }

    public void setFromMe(Collection<ExpressSheet> fromMe) {
        this.fromMe = fromMe;
    }

    @JsonIgnore
    @OneToMany(mappedBy = "reveiver")
    public Collection<ExpressSheet> getToMe() {
        return toMe;
    }

    public void setToMe(Collection<ExpressSheet> toMe) {
        this.toMe = toMe;
    }
}
